package com.credithc.customers.base.ro;

import com.credithc.customers.base.codes.CustomerCodes;
import com.credithc.customers.base.constants.CustomerConstants;
import com.credithc.customers.base.exception.CustomerException;
import com.credithc.customers.base.utils.CustomerUtils;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * @description: 客户基础信息表
 * @author: denghx
 * @date: 2018/11/28 10:33
 * @param: null
 * @return:
 */
@Data
public class CustomerInfoRo extends CustomerBaseRo {

    String preCustomerNo;

    String phone;

    String customerType;

    String remark;

    String accessToken;

    private CustomerIdInfoRo idInfo;

    private CompanyIdInfoRo companyIdInfo;

    private List<ContactRo> contacts;


    public static void checkBaseParam(CustomerInfoRo ro) {
        CustomerUtils.checkRequestNo(ro.getRequestNo());
        CustomerUtils.checkCustomerType(ro.getCustomerType());
        if (ro.getCustomerType().equals(CustomerConstants.CUSTOMER_TYPE_PERSON)) {
            if (ro.getIdInfo() == null) {
                throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "个人客户证件信息不能为空");
            } else {
                CustomerIdInfoRo.checkBaseParam(ro.getIdInfo());
            }
        } else {
            if (ro.getCompanyIdInfo() == null) {
                throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "企业客户证件信息不能为空");
            } else {
                CompanyIdInfoRo.checkBaseParam(ro.getCompanyIdInfo());
            }
        }
        if (StringUtils.isNotBlank(ro.getPhone())) {
            CustomerUtils.checkContactInfo(ro.getPhone());
            CustomerUtils.checkMobil(ro.getPhone());
        }
    }

}
